package com.lj.controller;

import com.github.pagehelper.PageInfo;
import com.lj.pojo.Clientlj;
import com.lj.pojo.Managerlj;
import com.lj.pojo.Stafflj;
import com.lj.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/manager")
public class ManagerAction {
    public static final int PAGE_SIZE=5;
    @Autowired
    ManagerService managerService;
    @RequestMapping("/selectManager")
    public String selectManager(HttpServletRequest request){
        //得到第一页数据
        PageInfo info=managerService.selectManager(1,PAGE_SIZE);
        request.setAttribute("info",info);
        return "admin/managerView";
    }
    //ajax分页翻页处理
    @ResponseBody
    @RequestMapping("/ajaxSplit")
    public void ajaxSplit(int page, HttpSession session){
        //取得当前page参数页面的数据
        PageInfo info=managerService.selectManager(page,PAGE_SIZE);
        session.setAttribute("info",info);
    }
    @RequestMapping(value = "/insert")
    public String insert(Managerlj managerlj){
        if(managerlj.getDirectorId().equals("null")){
            managerlj.setDirectorId(null);
        }
        int num=-1;
        num=managerService.insertManager(managerlj);
        return "redirect:/manager/selectManager.action";
    }
    @RequestMapping("/delete")
    public String delete(String managerId){
        int nums=-1;
        nums=managerService.delete(managerId);
        return"forward:/manager/selectManager.action";
    }
    @ResponseBody
    @RequestMapping("/getManagerById")
    public Managerlj getManagerById(String managerId, HttpServletRequest request ){
        Managerlj managerlj=managerService.getById(managerId);
        return managerlj;
    }
    @RequestMapping("/update")
    public String update(Managerlj managerlj){
        if(managerlj.getDirectorId().equals("null")){
            managerlj.setDirectorId(null);
        }
        int nums= managerService.update(managerlj);
        return "redirect:/manager/selectManager.action";
    }
}
